﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InSimDotNet.Packets;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace LFSRecord2.Model.Replay
{
    /// <summary>
    /// Class that holds the data of a player from a replay
    /// </summary>
    public class ReplayPlayerData
    {
        /// <summary>
        /// The PLID as assigned by LFS.
        /// </summary>
        public int PlayerID { get; private set; }

        /// <summary>
        /// The name of the player (when he joined)
        /// </summary>
        public string PlayerName { get; set; }

        /// <summary>
        /// Collection of ReplayDataNode s (packet + time indicator) recorded for this player.
        /// </summary>
        public Collection<ReplayDataNode> DataNodes { get; private set; }

        /// <summary>
        /// Internal variable used to track the time while recording.
        /// </summary>
        //private double _currentRecordTime = 0.0d;

        public ReplayPlayerData(int playerID) 
            : this(playerID, "")
        {
        }

        public ReplayPlayerData(int playerID, string playerName)
        {
            Debug.WriteLine("ReplayPlayerName : " + playerName);
            PlayerID = playerID;
            PlayerName = playerName;
            DataNodes = new Collection<ReplayDataNode>();
        }

        public ReplayDataNode FirstMciNode()
        {
            foreach (ReplayDataNode rNode in DataNodes)
            {
                if (rNode.IsMciNode)
                    return rNode;
            }
            return null;
        }
    }

    /// <summary>
    /// A data frame contains the frame time (time into the replay this packet was sent) and the packet itself.
    /// </summary>
    public class ReplayDataNode
    {
        public double ReplayTime { get; set; }
        public IPacket Packet { get; set; }
        public CompCarCustom MciInfo { get; set; }

        public bool IsMciNode
        {
            get
            {
                return (MciInfo != null);
            }
        }
    }
}
